package com.googlecode.jawb.tests.saving2;

import static org.junit.Assert.assertArrayEquals;

import java.io.ByteArrayOutputStream;

import org.junit.Test;

import com.googlecode.jawb.BinaryType;
import com.googlecode.jawb.JAWB;
import com.googlecode.jawb.clues.SetArray;
import com.googlecode.jawb.clues.SetType;

public class Saving2 {
	@SetType(type = BinaryType.UINT_8)
	@SetArray()
	private short values[] = {1, 2, 3, 4, 5};
	
	@SetType(type = BinaryType.OBJECT)
	@SetArray()
	private Foo foos[] = new Foo[3];
	
	public Saving2() {
		for (int i = 0; i < 3; i++) {
			foos[i] = new Foo();
		}
	}
	
	@Test()
	public void test() throws Exception {
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
		new JAWB().saveTo(outputStream, new Saving2());
		
		assertArrayEquals(outputStream.toByteArray(), new byte[]{
			1, 2, 3, 4, 5,
			1, 2, 3,
			1, 2, 3,
			1, 2, 3
		});
	}
}
